package com.baizhi.service;

import com.baizhi.dao.UserFigureMapper;
import com.baizhi.entity.UserFigure;
import com.baizhi.entity.UserFigureExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service("userFigureService")
@Transactional
public class UserFigureServiceImpl implements UserFigureService {

    @Resource
    private UserFigureMapper userFigureMapper;

    @Override
    public List<UserFigure> findAll() {
        UserFigureExample userFigureExample = new UserFigureExample();
        return userFigureMapper.selectByExample(userFigureExample);
    }

    @Override
    public List<UserFigure> findByUserId(String userId) {
        UserFigureExample userFigureExample = new UserFigureExample();
        userFigureExample.createCriteria().andUseridEqualTo(userId);
        return userFigureMapper.selectByExample(userFigureExample);
    }

    @Override
    public UserFigure findById(String id) {
        return userFigureMapper.selectByPrimaryKey(id);
    }

    @Override
    public void save(UserFigure userFigure) {
        userFigure.setId(UUID.randomUUID().toString());
        userFigureMapper.insert(userFigure);
    }

    @Override
    public void update(UserFigure userFigure) {
        userFigureMapper.updateByPrimaryKeySelective(userFigure);
    }

    @Override
    public void delete(String id) {
        userFigureMapper.deleteByPrimaryKey(id);
    }
}
